<template>
  <div class="login">
    <div class="login-content">
      <div class="fd-title fd-title-fy">
        {{ fy }}
        <span class="fd-title-xt">{{ title }}</span>
      </div>
      <div class="login_con_bg">
        <div class="login_con-content">
          <img src="@/images/icon-update/icon-bg-left-ct.png" alt="">
          <div class="login_con">
            <div class="l_con">
              <span id="download_error" class="error_download"></span>
              <div class="fd-tab">
                <p class="fd-login-name">欢迎登录</p>
              </div>
              <div class="dl_con">
                <div class="fd-form-row">
                  <span class="fd-label"></span>
                  <input id="username1" type="text"
                         v-model="form.username" class="dl_input" placeholder="账号"
                         @keydown.enter="onClickLogin">
                  <input name="username" id="username" type="hidden">
                </div>
                <div class="fd-form-row">
                  <span class="fd-label  fd-pw"></span>
                  <input id="password1" type="password" v-model="form.password" class="dl_input" placeholder="密码"
                         @keydown.enter="onClickLogin">
                  <input name="password" id="password" type="hidden">
                </div>
                <div class="dl_cz">
                  <div class="error_td">
                    <div id="tips" class="tips" align="left" style="display: none;font-size:11px;">
                      系统检测您已从其他地方登录或超时登录
                    </div>
                  </div>
                </div>
                <button type="primary" class="buttonCss" @click="onClickLogin">登录</button>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="fd-company">
      <p></p>
    </div>
  </div>
</template>

<script>

import api from "@/utils/api";
import obj from "@/json/db/user.json";
import user from "@/json/db/user.json";
import Vue from "vue";

export default {
  name: 'Login',
  data() {
    return {
      form: {
        username: 'admin',
        password: ''
      },
      title: '全流程智能化审判监督平台',
      fy: '青海省高级人民法院'
    }
  },
  mounted() {
    if ($ktType == 5) {
      this.title = $project_title_5
    }
    this.fy = $ktFy
  },
  methods: {
    alertSuccess(msg) {
      this.$message({
        message: msg,
        type: 'success'
      })
    },
    alertError(msg) {
      this.$message({
        message: msg,
        type: 'error'
      })
    },
    addLog(){
      const user = require("@/json/db/user.json")
      const obj = {}
      obj.module = '系统登录'
      obj.content = '登录了系统'
      obj.userName = user.userName
      api.addLog(obj);
    },
    async onClickLogin() {



      if (this.form.username === '') {
        this.alertError('用户名不能为空!')
        return
      }
      if (this.form.password === '') {
        this.alertError('密码不能为空!')
        return
      }
      // if (this.form.username !== 'admin') {
      //   this.alertError('该账号不存在!')
      //   return
      // }
      if (this.form.password !== '123') {
        this.alertError('密码输入有误!')
        return
      }
      //const obj = require("@/json/db/user.json")
      Vue.prototype.$globalUserId = this.form.username
      // api.addUser(obj);
      // this.addLog()
      this.$router.push({path: '/menu-v1'});


      // if (this.form.username === '') {
      //   this.$message({
      //     type: 'warning',
      //     message: '账号不能为空'
      //   })
      //   return
      // }
      /*if (this.form.password === '') {
        this.$message({
          type: 'warning',
          message: '密码不能为空'
        })
        return
      }*/
      //测试账号
      // var userInfo_yz = { 'username': 'yz', 'name': '王xx', 'role': 'yz', 'rolename': '院长' }
      // var userInfo_sgb = { 'username': 'sgb', 'name': '何xx', 'role': 'sgb', 'rolename': '审管办' }
      // var userInfo_jjz = { 'username': 'jjz', 'name': '张xx', 'role': 'jjz', 'rolename': '纪检组' }
      // var userInfo_dcs = { 'username': 'dcs', 'name': '陆xx', 'role': 'dcs', 'rolename': '督查室' }
      // if (this.form.username == 'admin' || this.form.username == 'yz') {
      //   localStorage.setItem('userInfo', JSON.stringify(userInfo_yz))
      // } else if (this.form.username == 'sgb') {
      //   localStorage.setItem('userInfo', JSON.stringify(userInfo_sgb))
      // } else if (this.form.username == 'jjz') {
      //   localStorage.setItem('userInfo', JSON.stringify(userInfo_jjz))
      // } else if (this.form.username == 'dcs') {
      //   localStorage.setItem('userInfo', JSON.stringify(userInfo_dcs))
      // }
      // if ($ktType == 5) {
      //   this.$router.push({
      //     path: '/gl5'
      //   })
      // }
      // return

      // await login(this.form).then((res) => {
      //   console.log('login=', res)
      //   if (res.code == 200) {
      //     localStorage.setItem('token', res.token)
      //
      //     var _this = this
      //     getLoginUserInfo().then((res) => {
      //       console.log('getLoginUserInfo=', res)
      //       var userInfo = res
      //       if (userInfo.role == 'admin') {
      //         userInfo.isAdmin = true
      //         localStorage.setItem('userInfo', JSON.stringify(userInfo))
      //       }
      //       if (userInfo.role == 'common') {
      //         userInfo.isAdmin = false
      //         localStorage.setItem('userInfo', JSON.stringify(userInfo))
      //       }
      //       this.$router.push({
      //         path: '/sy'
      //       })
      //     }).catch((err) => {
      //       this.$message({
      //         type: 'error',
      //         message: err
      //       })
      //     })
      //   }
      //   if (res.code == 500) {
      //     this.$message({
      //       type: 'error',
      //       message: res.msg
      //     })
      //   }
      // }).catch((err) => {
      //   this.$message({
      //     type: 'error',
      //     message: err
      //   })
      // })
    }
  }
}
</script>

<style scoped src="../../styles/login.css"></style>
<style>
.buttonCss {
  width: 300px;
  height: 40px;
  cursor: pointer;
  margin-right: 60px;
  color: #fff;
  background-color: #1880ff;
  border-color: #1880ff;
  border-radius: 4px;
  font-weight: 400;
}

</style>
